// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import zombie.characters.IsoPlayer;
import zombie.commands.AltCommandArgs;
import zombie.commands.CommandArgs;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.CommandNames;
import zombie.commands.RequiredRight;
import zombie.core.logger.LoggerManager;
import zombie.core.raknet.UdpConnection;
import zombie.network.GameServer;

@CommandNames({@CommandName(
        name = "godmod"
    ), @CommandName(
        name = "godmode"
    )})
@AltCommandArgs({@CommandArgs(
        required = {"(.+)"},
        optional = "(-true|-false)"
    ), @CommandArgs(
        optional = "(-true|-false)"
    )})
@CommandHelp(
    helpText = "UI_ServerOptionDesc_GodMod"
)
@RequiredRight(
    requiredRights = 62
)
public class GodModeCommand extends CommandBase {
    public GodModeCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    @Override
    protected String Command() {
        String string0 = this.getExecutorUsername();
        String string1 = this.getCommandArg(Integer.valueOf(0));
        String string2 = this.getCommandArg(Integer.valueOf(1));
        if (this.getCommandArgsCount() == 2 || this.getCommandArgsCount() == 1 && !string1.equals("-true") && !string1.equals("-false")) {
            string0 = string1;
            if (this.connection != null && this.connection.accessLevel == 2 && !string1.equals(string1)) {
                return "An Observer can only toggle god mode on himself";
            }
        }

        IsoPlayer isoPlayer = GameServer.getPlayerByUserNameForCommand(string0);
        if (isoPlayer != null) {
            string0 = isoPlayer.getDisplayName();
            if (string2 != null) {
                isoPlayer.setGodMod("-true".equals(string2));
            } else {
                isoPlayer.setGodMod(!isoPlayer.isGodMod());
            }

            GameServer.sendPlayerExtraInfo(isoPlayer, this.connection);
            if (isoPlayer.isGodMod()) {
                LoggerManager.getLogger("admin").write(this.getExecutorUsername() + " enabled godmode on " + string0);
                return "User " + string0 + " is now invincible.";
            } else {
                LoggerManager.getLogger("admin").write(this.getExecutorUsername() + " disabled godmode on " + string0);
                return "User " + string0 + " is no more invincible.";
            }
        } else {
            return "User " + string0 + " not found.";
        }
    }
}
